import * as echarts from 'echarts'
import { debounce } from '@/utils/old-methods'

export default function (el: any) {
  const echartInstance = echarts.init(el)

  const setOptions = (options: any) => {
    echartInstance.setOption(options)
  }

  const updateSize = () => {
    echartInstance.resize()
  }

  window.addEventListener('resize', () => {
    debounce(echartInstance.resize, 300)()
  })

  return {
    echartInstance,
    setOptions,
    updateSize
  }
}
